package main

import "fmt"

// Product: House
type House struct {
	Foundation string
	Structure  string
	Roof       string
}

// Builder: 抽象建造者接口
type HouseBuilder interface {
	BuildFoundation()
	BuildStructure()
	BuildRoof()
	GetResult() House
}

// ConcreteBuilder: 具体建造者
type ConcreteHouseBuilder struct {
	house House
}

func (b *ConcreteHouseBuilder) BuildFoundation() {
	b.house.Foundation = "Concrete and Steel Foundation"
	fmt.Println("Foundation built.")
}

func (b *ConcreteHouseBuilder) BuildStructure() {
	b.house.Structure = "Reinforced Concrete Framework"
	fmt.Println("Structure built.")
}

func (b *ConcreteHouseBuilder) BuildRoof() {
	b.house.Roof = "Slab Roof"
	fmt.Println("Roof built.")
}

func (b *ConcreteHouseBuilder) GetResult() House {
	return b.house
}

// Director: 指挥者
type Director struct {
	builder HouseBuilder
}

func (d *Director) SetBuilder(builder HouseBuilder) {
	d.builder = builder
}

func (d *Director) ConstructHouse() {
	d.builder.BuildFoundation()
	d.builder.BuildStructure()
	d.builder.BuildRoof()
}

func main() {
	// 创建具体建造者
	builder := &ConcreteHouseBuilder{}

	// 使用指挥者构建对象
	director := &Director{}
	director.SetBuilder(builder)
	director.ConstructHouse()

	// 获取最终的房屋产品
	house := builder.GetResult()
	fmt.Println("Final House:", house)
}
